package com.tbitsglobal.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class LoginPage extends Composite{
	TextBox nickBox;
	String login = null;
	
	public LoginPage()
	{
		Label nickLabel = new Label("Nickname:");
		nickBox = new TextBox();
		
		Button button = new Button("Login");
		button.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				String nick = nickBox.getText();
				if(!tryCreatingNick(nick))
				{
					Window.alert("Nickname " + nick + " already exists.");
				}
				else
				{
					login = nick;
					login();
				}
			}

			private void login() {
				// TODO Auto-generated method stub
				Talk.get().goHome();
				//make call to the entry level app which should be a singleton. and ask it to start chat.
			}

			private boolean tryCreatingNick(String nick) {
				// TODO Auto-generated method stub
				return true;
			}
			
		});
		
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
		vPanel.add(nickLabel);
		vPanel.add(nickBox);
		vPanel.add(button);
		
		//listUser = new ListBox(false);
		//loadUsers();
		DockPanel p = new DockPanel();
		//p.add(listUser, DockPanel.WEST);
		p.add(vPanel, DockPanel.CENTER);
		
		initWidget(p);
	}
	
}